<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>First Allreduce Application | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="该篇文章介绍MPICH在Linux和Windows的安装以及一个最简单的Allreduce的例程">
<meta property="og:type" content="article">
<meta property="og:title" content="First Allreduce Application">
<meta property="og:url" content="https://chudod.gitee.io/myworks/2022/03/30/First_MPI_Program/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="该篇文章介绍MPICH在Linux和Windows的安装以及一个最简单的Allreduce的例程">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB20896ad49caab7166ef314cad41a02b6?method=download&shareKey=904f976c5859bc89c59dc0453602ff98">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB7c6b5b95675ec4f841346e261f69ce27?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB6d1c0e875e7a9f657caabefebba78720?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEBf74acea7bf53fffaa844e63a7dec88c0?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEBe948b4c6c4177ceb858b5b701b2c30d5?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB20c39cee8383c7ff5aa58051b1813587?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB3649df78f08d5e177074bb94203e796c?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB40a3f1b4bf58bf1355913ab011d39dba?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB45e6a730d39c84744f498943cede91f3?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEBb24da11e6a4661787def0934cdfbe1fd?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB45f2da6f8a6933d86356422c763a9d35?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB2a2c779942cc9145ed1cb903c51aa7e3?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEBf9d84e95565cd0cf872f810f043ea6ed?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB635e35297acaeac7ad5f79fc97142fab?method=download&shareKey=0412dcb1d5f95516723864a4f1a48a13">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB8453078f33cba2dcd2ba5b49d8b04daf?method=download&shareKey=0412dcb1d5f95516723864a4f1a48a13">
<meta property="article:published_time" content="2022-03-29T16:00:00.000Z">
<meta property="article:modified_time" content="2022-04-10T13:21:36.606Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="MPI">
<meta property="article:tag" content="并行计算">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://note.youdao.com/yws/api/personal/file/WEB20896ad49caab7166ef314cad41a02b6?method=download&shareKey=904f976c5859bc89c59dc0453602ff98">
  
    <link rel="alternate" href="/myworks/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/myworks/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/myworks/css/style.css">

  
    
<link rel="stylesheet" href="/myworks/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 6.2.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/myworks/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/myworks/">Home</a>
        
          <a class="main-nav-link" href="/myworks/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/myworks/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://chudod.gitee.io/myworks"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-First_MPI_Program" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/myworks/2022/03/30/First_MPI_Program/" class="article-date">
  <time class="dt-published" datetime="2022-03-29T16:00:00.000Z" itemprop="datePublished">2022-03-30</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/myworks/categories/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/">并行计算</a>►<a class="article-category-link" href="/myworks/categories/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/MPI%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/">MPI程序设计</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      First Allreduce Application
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="MPI安装"><a href="#MPI安装" class="headerlink" title="MPI安装"></a>MPI安装</h1><h2 id="Linux安装MPICH"><a href="#Linux安装MPICH" class="headerlink" title="Linux安装MPICH"></a>Linux安装MPICH</h2><p>$MPICH$是$MPI$的一个使用的非常广泛的库。简单的在$linux$中$sudo\ apt-get\ install$就可以安装成功，当然也可以下载$MPICH$源码，可参考<a target="_blank" rel="noopener" href="https://mpitutorial.com/tutorials/installing-mpich2/zh_cn/">MPICH安装</a></p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get update</span><br><span class="line">sudo apt-get install mpich</span><br></pre></td></tr></table></figure>
<p>通过在程序中添加</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;mpi.h&gt;</span></span></span><br></pre></td></tr></table></figure>
<p>即可调用$MPICH$，可以参考<a target="_blank" rel="noopener" href="https://mpitutorial.com/tutorials/mpi-hello-world/zh_cn/">这里</a>写第一个简单的$MPI\ Hello\ World$程序。<br>$mpicc$和$mpicxx$是$MPICH$的编译器，看名字就知道分别对应$C$和$C++$程序。简单使用</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mpicc helloworld.c -o helloworld</span><br></pre></td></tr></table></figure>
<p>就可以编译程序，再使用</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mpirun -n <span class="number">4</span> helloworld</span><br></pre></td></tr></table></figure>
<p>就可以运行$mpi$程序，$mpiexec$和$mpirun$是$MPICH$提供的两个解释器，能够运行我们编写的应用程序，其中$mpirun$只能使每个进程运行同一个程序，而$mpiexec$能使不同进程运行不同的程序，如</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mpiexec -n <span class="number">1</span> program1 : -n <span class="number">2</span> porgram2</span><br></pre></td></tr></table></figure>
<h1 id="Windows安装MPI"><a href="#Windows安装MPI" class="headerlink" title="Windows安装MPI"></a>Windows安装MPI</h1><h2 id="下载MPICH"><a href="#下载MPICH" class="headerlink" title="下载MPICH"></a>下载MPICH</h2><p>在<a target="_blank" rel="noopener" href="https://www.mpich.org/downloads/">MPICH官网</a>下载源码包，选择$Windows$系统，然后在这里点击$http$。<img src="https://note.youdao.com/yws/api/personal/file/WEB20896ad49caab7166ef314cad41a02b6?method=download&shareKey=904f976c5859bc89c59dc0453602ff98"><br>再选择这里的安装：<br><img src="https://note.youdao.com/yws/api/personal/file/WEB7c6b5b95675ec4f841346e261f69ce27?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"><br>把两个安装程序都装上：<br><img src="https://note.youdao.com/yws/api/personal/file/WEB6d1c0e875e7a9f657caabefebba78720?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"><br>分别点击两个安装程序，生成如下两个文件夹（可以放在D盘，自己命名文件夹）:<br><img src="https://note.youdao.com/yws/api/personal/file/WEBf74acea7bf53fffaa844e63a7dec88c0?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"></p>
<h2 id="在Visual-Studio中配置环境"><a href="#在Visual-Studio中配置环境" class="headerlink" title="在Visual Studio中配置环境"></a>在Visual Studio中配置环境</h2><p>在$Visual Studio$中“创建新项目”-&gt;“控制台应用”。我得项目名字叫“MPITest”，然后选择“调试”-&gt;“调试属性”。<br><img src="https://note.youdao.com/yws/api/personal/file/WEBe948b4c6c4177ceb858b5b701b2c30d5?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"><br>选择“C&#x2F;C++”-&gt;“预处理器”-&gt;“预处理器定义”-&gt;添加“MPICH_SKIP_MPICXX”<br><img src="https://note.youdao.com/yws/api/personal/file/WEB20c39cee8383c7ff5aa58051b1813587?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"><br>选择“代码生成”-&gt;“运行库”-&gt;“多线程调试\MTD”：<br><img src="https://note.youdao.com/yws/api/personal/file/WEB3649df78f08d5e177074bb94203e796c?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"><br>选择“输入”-&gt;“添加附加依赖项”-&gt;添加“msmpi.lib”<br><img src="https://note.youdao.com/yws/api/personal/file/WEB40a3f1b4bf58bf1355913ab011d39dba?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"><br>选择“VC++目录”-&gt;“包含目录”-&gt;添加“(MPI安装位置)\Microsoft SDKs\Include”；<br><img src="https://note.youdao.com/yws/api/personal/file/WEB45e6a730d39c84744f498943cede91f3?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"><br>再选择“库目录”-&gt;添加“(MPI安装位置)\Microsoft SDKs\Lib\x64”<br><img src="https://note.youdao.com/yws/api/personal/file/WEBb24da11e6a4661787def0934cdfbe1fd?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"><br>配置完成。</p>
<h2 id="运行方法"><a href="#运行方法" class="headerlink" title="运行方法"></a>运行方法</h2><h3 id="使用cmd终端或者Powershell终端运行"><a href="#使用cmd终端或者Powershell终端运行" class="headerlink" title="使用cmd终端或者Powershell终端运行"></a>使用cmd终端或者Powershell终端运行</h3><p>按照下一节的$Allreduce$积分程序写好代码，然后$VS$里点击运行，生成$.exe$文件，由于$VS$的默认进程数是1，只能运行进程数为1的情况。<br><img src="https://note.youdao.com/yws/api/personal/file/WEB45f2da6f8a6933d86356422c763a9d35?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"><br>打开cmd终端，在$.exe$文件的目录下输入指令</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mpiexec -n <span class="number">4</span> MPITest.exe</span><br></pre></td></tr></table></figure>
<p>得到结果:<br><img src="https://note.youdao.com/yws/api/personal/file/WEB2a2c779942cc9145ed1cb903c51aa7e3?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"></p>
<h3 id="在VS里配置命令"><a href="#在VS里配置命令" class="headerlink" title="在VS里配置命令"></a>在VS里配置命令</h3><p>复制$MPITest.exe$程序到$C$盘，然后点击“MPITest项目属性”-&gt;“调试”，配置命令行属性如图即可。注意命令参数是“mpiexec.exe”程序所在的文件夹，在最开始生成的两个安装文件包的“Microsoft MPI”里，并且$MPITest.exe$程序一定要拷贝到$C$盘！！！不然$VS$会报错找不到这个$MPITest.exe$程序，不知道为什么会有这个$bug$。<br><img src="https://note.youdao.com/yws/api/personal/file/WEBf9d84e95565cd0cf872f810f043ea6ed?method=download&shareKey=707ee3c6204b8e72dfaa8e511c794021"></p>
<h1 id="First-Allreduce-Program"><a href="#First-Allreduce-Program" class="headerlink" title="First Allreduce Program"></a>First Allreduce Program</h1><p>这里展示调用$MPI$_ $Allreduce$函数来使用梯形积分法求解$\int_{1}^{e}\ln{x}dx$。<br>$Allreduce$操作是$MPI$中最常用的集合通信操作，与之相似的是$Reduce$操作，假设有$p$个进程，每个进程都持有一个含$n$个元素的向量，所有的$p$个进程将自己的向量发送给根进程，根进程收集这些向量计算规约的结果（求和、求最大最小值等等），$Reduce$操作结果保存在根进程，$Allreduce$则将根进程的结果再广播出去。简单的在应用程序中调用$MPI$_$Allreduce$就可以完成上述例程，函数定义如下：<br>程序可以表示为：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">int</span> <span class="title">MPI_Allreduce</span><span class="params">(</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="type">const</span> <span class="type">void</span> *sendbuf,      <span class="comment">//存放源数据</span></span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="type">void</span> *recvbuf,            <span class="comment">//存放规约结果</span></span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="type">int</span> count,                <span class="comment">//数据个数</span></span></span></span><br><span class="line"><span class="params"><span class="function">            MPI_Datatype datatype,    <span class="comment">//数据类型</span></span></span></span><br><span class="line"><span class="params"><span class="function">            MPI_Op op,                <span class="comment">//规约操作类型</span></span></span></span><br><span class="line"><span class="params"><span class="function">            MPI_Comm comm)</span></span>;           <span class="comment">//一组通信进程</span></span><br></pre></td></tr></table></figure>
<p>$MPI$<em>$Reduce$ 和$MPI$</em>$Allreduce$例程的图解如下所示：</p>
<div style="align: center">
<img src="https://note.youdao.com/yws/api/personal/file/WEB635e35297acaeac7ad5f79fc97142fab?method=download&shareKey=0412dcb1d5f95516723864a4f1a48a13" width="70%" height="70%"/>
</div>

<div style="align: center">
<img src="https://note.youdao.com/yws/api/personal/file/WEB8453078f33cba2dcd2ba5b49d8b04daf?method=download&shareKey=0412dcb1d5f95516723864a4f1a48a13" width="70%" height="70%"/>
</div>

<p>图片源网址和$MPI$_$Allreduce$的入门教程在这里：<a target="_blank" rel="noopener" href="https://mpitutorial.com/tutorials/mpi-reduce-and-allreduce/">英文版</a>和<a target="_blank" rel="noopener" href="https://mpitutorial.com/tutorials/mpi-reduce-and-allreduce/zh_cn/">中文版</a> </p>
<p>利用梯形积分法求解$\int_{1}^{e}\ln{x}dx$的思路是将区间$[1,e]$分成1024个段，一个段对应一个狭小的梯形，面积为$\ln{x_i}\cdot{dx}$，然后将这些梯形相加。$MPI$可以创建多个进程来加速，每个进程计算一部分区间的积分，然后将结果相加起来。在程序中$a$和$b$是整个积分的区间，$local$_ $a$和$local$_$b$是每个进程负责的区间。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;math.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;mpi.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">define</span>	   e	exp(1)</span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span>  n = <span class="number">1024</span>, local_n;</span><br><span class="line"><span class="type">double</span>  a = <span class="number">1.0</span>, b = e, len;</span><br><span class="line"><span class="type">double</span>  local_a, local_b, sum = <span class="number">0.0</span>, ans, local_ans;</span><br><span class="line"></span><br><span class="line"><span class="type">double</span>  <span class="title function_">calc</span><span class="params">(<span class="type">double</span>  local_a, <span class="type">double</span>  local_b, <span class="type">int</span>  local_n)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">double</span> sum = (<span class="built_in">log</span>(local_a) + <span class="built_in">log</span>(local_b)) / <span class="number">2</span>;</span><br><span class="line">	<span class="type">int</span> i;</span><br><span class="line">	<span class="type">double</span> xi;</span><br><span class="line">	<span class="keyword">for</span> (i = <span class="number">1</span>; i &lt; local_n; i++)</span><br><span class="line">	&#123;</span><br><span class="line">		xi = local_a + len * i;</span><br><span class="line">		sum += <span class="built_in">fabs</span>(<span class="built_in">log</span>(xi));</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span>  sum * len;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span>  comm_size;</span><br><span class="line">	<span class="type">int</span>  my_rank;</span><br><span class="line">	MPI_Init(<span class="literal">NULL</span>, <span class="literal">NULL</span>);</span><br><span class="line">	MPI_Comm_size(MPI_COMM_WORLD, &amp;comm_size);</span><br><span class="line">	MPI_Comm_rank(MPI_COMM_WORLD, &amp;my_rank);</span><br><span class="line"></span><br><span class="line">	len = (b - a) / n;		<span class="comment">//就是dx</span></span><br><span class="line">	local_a = a + my_rank * len * (n / comm_size);		<span class="comment">//local_a是每个进程负责计算的区间的起始</span></span><br><span class="line">	local_b = local_a + len * (n / comm_size);		<span class="comment">//local_b是每个进程负责计算的区间的结束</span></span><br><span class="line">	local_n = n / comm_size;</span><br><span class="line"></span><br><span class="line">	<span class="comment">//每个进程计算自己区间上的积分</span></span><br><span class="line">	local_ans = calc(local_a, local_b, local_n);	</span><br><span class="line">	<span class="comment">//每个进程计算的结果local_ans相加到全局结果ans上	</span></span><br><span class="line">	MPI_Allreduce(&amp;local_ans, &amp;ans, <span class="number">1</span>, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);</span><br><span class="line"></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;My rank: %d, Result : %.5f\n&quot;</span>, my_rank, ans);</span><br><span class="line">	MPI_Finalize();</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在$Linux$中编译时链接上$lm$数学运算库：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mpicc allreduce.c -o allreduce -lm</span><br><span class="line">mpiexec -n <span class="number">4</span> allreduce</span><br></pre></td></tr></table></figure>
<p>即可得到结果。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://chudod.gitee.io/myworks/2022/03/30/First_MPI_Program/" data-id="cl3kznqzv0006j0uk4e5u205v" data-title="First Allreduce Application" class="article-share-link">Share</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/myworks/tags/MPI/" rel="tag">MPI</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/myworks/tags/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/" rel="tag">并行计算</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/myworks/2022/03/30/Deeply_Understand_MPI/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          深入理解MPI实现
        
      </div>
    </a>
  
  
    <a href="/myworks/2022/03/27/MPI_Allreduce_Summary/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">MPI_Allreduce的前世今生</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/English/">English</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D1%8F/">Россия</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E5%AF%BC%E8%88%AA/">导航</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/">并行计算</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/In-Network-Collectives/">In-Network Collectives</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/MPI%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/">MPI程序设计</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/MPI%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E4%B8%8E%E5%B9%B6%E8%A1%8C%E7%AE%97%E6%B3%95/">MPI程序设计与并行算法</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/MPI%E8%BD%AF%E4%BB%B6%E6%A0%88%E8%AE%BE%E8%AE%A1/">MPI软件栈设计</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/MPI%E9%9B%86%E5%90%88%E9%80%9A%E4%BF%A1%E7%AE%97%E6%B3%95/">MPI集合通信算法</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/Topology-Aware-Algorithms/">Topology-Aware Algorithms</a></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E6%95%B4%E6%B4%BB%E7%B3%BB%E5%88%97/">整活系列</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E7%A1%AC%E6%A0%B8%E7%8B%A0%E4%BA%BA/">硬核狠人</a></li><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/">计算机基础知识</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/myworks/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/">操作系统</a></li></ul></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/English-Vocabulary/" rel="tag">English Vocabulary</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/English-Writing/" rel="tag">English Writing</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/MPI/" rel="tag">MPI</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/Topology-Aware/" rel="tag">Topology-Aware</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D1%8F/" rel="tag">Россия</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%E5%9C%A8%E7%BD%91%E8%AE%A1%E7%AE%97/" rel="tag">在网计算</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%E5%B9%B6%E8%A1%8C%E7%AE%97%E6%B3%95/" rel="tag">并行算法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/" rel="tag">并行计算</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag">操作系统</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%E6%95%B4%E6%B4%BB/" rel="tag">整活</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%E7%94%9F%E6%B4%BB/" rel="tag">生活</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%E7%A1%AC%E6%A0%B8%E7%8B%A0%E4%BA%BA/" rel="tag">硬核狠人</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%E9%9B%86%E5%90%88%E9%80%9A%E4%BF%A1/" rel="tag">集合通信</a></li><li class="tag-list-item"><a class="tag-list-link" href="/myworks/tags/%E9%AB%98%E6%80%A7%E8%83%BD%E8%AE%A1%E7%AE%97/" rel="tag">高性能计算</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/myworks/tags/English-Vocabulary/" style="font-size: 10px;">English Vocabulary</a> <a href="/myworks/tags/English-Writing/" style="font-size: 10px;">English Writing</a> <a href="/myworks/tags/MPI/" style="font-size: 17.5px;">MPI</a> <a href="/myworks/tags/Topology-Aware/" style="font-size: 10px;">Topology-Aware</a> <a href="/myworks/tags/%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D1%8F/" style="font-size: 12.5px;">Россия</a> <a href="/myworks/tags/%E5%9C%A8%E7%BD%91%E8%AE%A1%E7%AE%97/" style="font-size: 12.5px;">在网计算</a> <a href="/myworks/tags/%E5%B9%B6%E8%A1%8C%E7%AE%97%E6%B3%95/" style="font-size: 10px;">并行算法</a> <a href="/myworks/tags/%E5%B9%B6%E8%A1%8C%E8%AE%A1%E7%AE%97/" style="font-size: 20px;">并行计算</a> <a href="/myworks/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" style="font-size: 15px;">操作系统</a> <a href="/myworks/tags/%E6%95%B4%E6%B4%BB/" style="font-size: 10px;">整活</a> <a href="/myworks/tags/%E7%94%9F%E6%B4%BB/" style="font-size: 10px;">生活</a> <a href="/myworks/tags/%E7%A1%AC%E6%A0%B8%E7%8B%A0%E4%BA%BA/" style="font-size: 10px;">硬核狠人</a> <a href="/myworks/tags/%E9%9B%86%E5%90%88%E9%80%9A%E4%BF%A1/" style="font-size: 15px;">集合通信</a> <a href="/myworks/tags/%E9%AB%98%E6%80%A7%E8%83%BD%E8%AE%A1%E7%AE%97/" style="font-size: 12.5px;">高性能计算</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/myworks/archives/2022/05/">May 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/myworks/archives/2022/04/">April 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/myworks/archives/2022/03/">March 2022</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/myworks/2022/05/24/Russian_Grammar/">Русская Граммаатика(俄语语法)</a>
          </li>
        
          <li>
            <a href="/myworks/2022/05/18/OS_FileSystem/">文件系统概念和Ext2文件系统</a>
          </li>
        
          <li>
            <a href="/myworks/2022/05/14/English_Sentences/">English Sentences</a>
          </li>
        
          <li>
            <a href="/myworks/2022/05/11/English_Vocabulary/">English Vocabulary</a>
          </li>
        
          <li>
            <a href="/myworks/2022/05/11/Russian_Vocabulary/">Русские Слова(俄语单词)</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2022 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/myworks/" class="mobile-nav-link">Home</a>
  
    <a href="/myworks/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/myworks/js/jquery-3.4.1.min.js"></script>



  
<script src="/myworks/fancybox/jquery.fancybox.min.js"></script>




<script src="/myworks/js/script.js"></script>





  </div>
</body>
</html>